package com.ssg.poultry;

import java.util.List;

import org.apache.log4j.Logger;

import com.ssg.poultry.service.SerialPortService;

import gnu.io.SerialPort;

public class SerialPortTest {
	public static void main(String[] args) throws Exception {
		Logger logger = Logger.getLogger(SerialPortTest.class);
		logger.debug("start test");
		SerialPortService sps = new SerialPortService(115200, 1);

		List<String> ports = sps.listPortName();
		for (String p : ports) {
			logger.debug("p:" + p);
		}
		
		logger.debug("new service finished.");
		
		SerialPort port = sps.connPort("COM4");
		logger.debug("get Port:" + port);
		// AB 04 01 80 01 00
		byte[] conn = { (byte) 0XAB, 0X04, 0X01, (byte) 0X80, 0X01, 0X00 };
		logger.debug("start write conn.");
		sps.writeToPort(port, conn);
		logger.debug("write conn.");
		Thread.sleep(500);
		byte[] read = sps.readFromPort(port, 12);

		//寻卡
		//AB 04 01 00 03 80
		byte[] findCard = {(byte) 0XAB,0X04,0X01,0x00,0x03,(byte) 0x80};
		sps.writeToPort(port, findCard);
		Thread.sleep(2000);
		byte[] findCardResult = sps.readFromPort(port);
		

	}
}
